package com.sky.controller.admin;

import com.sky.constant.CacheConstants;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/5/21 15:58
 */
@RequestMapping("/admin/shop")
@RestController
@Slf4j
@Api(tags = "营业管理")
public class ShopController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 设置营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result setShopStatus(@PathVariable Integer status){
        if (status==null){
            throw new RuntimeException("参数异常");
        }
        stringRedisTemplate.opsForValue().set(CacheConstants.SHOP_STATUS, status.toString());
        return Result.success();
    }

    /**
     * 获取营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result getShopStatus(){

        String statusStr = stringRedisTemplate.opsForValue().get(CacheConstants.SHOP_STATUS);

        return Result.success(Integer.valueOf(statusStr));
    }
}
